package com.example.administrator.xiaobo.adapter.show_adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.xiaobo.R;
import com.example.administrator.xiaobo.bean.show_1Bean;
import com.example.administrator.xiaobo.bean.show_2Bean;
import com.example.administrator.xiaobo.bean.show_Bean;

/**
 * Created by Administrator on 2017/2/8.
 * 用于show中的viewType=1和viewType=2
 */

public class ShowAdapter1 extends RecyclerView.Adapter<ShowAdapter1.MyViewHolder> {
    private Context context;
    private show_Bean data;

    public ShowAdapter1(Context context, show_Bean data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.itme_show_0101,null);

        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        if (data instanceof show_1Bean) {
            show_1Bean show_1Bean = (show_1Bean) data;
            Glide.with(context).load(show_1Bean.list.get(position).level1).placeholder(R.drawable.type_1_man).error(R.drawable.type_1_man).into(holder.imageView);
            holder.textView.setText(show_1Bean.list.get(position).name);
        }else if (data instanceof show_2Bean){
            show_2Bean show_2Bean = (com.example.administrator.xiaobo.bean.show_2Bean) data;
            Glide.with(context).load(show_2Bean.list.get(position).level1).placeholder(R.drawable.type_1_man).error(R.drawable.type_1_man).into(holder.imageView);
            holder.textView.setText(show_2Bean.list.get(position).name);
        }
    }

    @Override
    public int getItemCount() {
        if (data instanceof show_1Bean) {
            return ((show_1Bean) data).list.size();
        }else{
            return ((show_2Bean) data).list.size();
        }
    }

    class MyViewHolder extends RecyclerView.ViewHolder{
        ImageView imageView;
        TextView textView;
        public MyViewHolder(View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView_show0101);
            textView = (TextView) itemView.findViewById(R.id.textView_show0101);
        }
    }
}
